package com.niit.TopOne.schooltopone;


import com.niit.bean.StudentBean;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;


public class SchoolTopOneMapper extends Mapper<LongWritable, Text, StudentBean, NullWritable> {

    StudentBean outKey = new StudentBean();
    NullWritable outValue = NullWritable.get();

    @Override
    protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
        String[] fields = value.toString().split(",");
        String City = fields[8];
        String School = fields[1];
        long ActiveDays =Long.parseLong(fields[10]);  //活跃天数
        for (String field : fields) {
            if ("未知".equals(field)) {
                return; // 如果发现"未知"，跳过这条记录
            }
        }
        outKey.set(City,School,ActiveDays);
        context.write(outKey,outValue);
    }

}
